/*
 * Clock.cpp
 *
 *  Created on: 28/04/2013
 *      Author: roger
 */

#include "Clock.h"

static char *clock_bitmap PROGMEM =
	"I[/DO,CYM\\/TR]@(!!!!!!!!@X^`!!!!IK+CDY_0O\\O\\O,CYGZO<S=H*FJ;7!!!!"
	"!!!!!!!!!!!!!!!!!!!!!1%\"!!!!!!!!!!!!!A)#!!!!!!!!````````````````"
	"````!!!!````!!!!````````````````````````C)C)W.D9KKKK!!!!!!!!!!!!"
	"!!!!!!!!!Q-$!!!!!!!!!!!!!!!!!!!!````````````````````!!!!````!!!!"
	"````````````````````````!!!!!!!!K+CIY?(B;WNL!!!!!!!!!!!!!!!!!!!!"
	"!A)#!!!!!!!!!!!!````````````````````!!!!!!!!!!!!!!!!````````````"
	"````!!!!!!!!!!!!!!!!PL[_L+SMP<W^!!!!!Q-$!!!!!!!!!!!!!1%\"!!!!!!!!"
	"````````````````````````````````````````````````````!!!!!!!!!!!!"
	"!!!!````````FZ?8O\\O\\!!!!!!!!!!!!!!!!!A)#!!!!!!!!````````````````"
	"````````````````````````````````!!!!!!!!!!!!!!!!````````````````"
	"P\\_`J+3E!!!!!!!!!!!!!!!!!1%\"!!!!````````````````````````````````"
	"````````````````!!!!````````!!!!````````````````````N,3UQ]0$!!!!"
	"!!!!!!!!!!!!!1%\"````````````````````````````````````````````````"
	"!!!!````````````````````````````````````F*35D)S-!!!!!!!!!Q-$!!!!"
	"````````````````````````````````````````````!!!!````````````````"
	"````````````````````````````V>86!!!!!!!!!A)#!!!!````````````````"
	"````````````````````````!!!!!!!!````````````````````````````````"
	"X^`@!!!!!!!!M,#QO<GZ!!!!!!!!!!!!````````````````````````````````"
	"````````!!!!````````````````````````````````````!!!!!!!!````!!!!"
	"N\\?X!!!!!!!!!!!!````````````````````````````````````````!!!!````"
	"````````````````````````````````````!!!!!!!!````M,#QJ;7F!!!!!!!!"
	"````````````````````````````````````!!!!!!!!````````````````````"
	"````````````````````````````````````N,3U!!!!!!!!````````````````"
	"````````````````````!!!!````````````!!!!!!!!!!!!!!!!!!!!````````"
	"````````````````````N<7V8FZ?!!!!````````````````````````````````"
	"!!!!!!!!````````!!!!!!!!!!!!!!!!!!!!````````````````````````````"
	"````N,3UDY_0!!!!````````````````````````````````!!!!````````!!!!"
	"!!!!!!!!!!!!!!!!!!!!````````````````````````````````````U>(2!!!!"
	"````````````````````````````````!!!!````!!!!!!!!!!!!!!!!!!!!````"
	"````````````````````````````````UN,3````ML+S!!!!````````````````"
	"````````````!!!!!!!!!!!!!!!!````````````````````````````````````"
	"````````!!!!!!!!!!!!!!!!X>X>!!!!````````````````````````!Q-$!!!!"
	"!!!!````````````````````````````````````````````````````````````"
	"````````N<7V!!!!````````````````````!!!!!!!!!!!!!!!!````````````"
	"````````````````````````````````````````!!!!!!!!!!!!!!!!Q=(\"!!!!"
	"````````````````````!!!!!!!!!!!!!!!!!!!!!!!!!!!!````````````````"
	"````````````````````````````````````````W>H:!!!!````````````````"
	"````````````````````!!!!````!!!!````````````````````````````````"
	"````````````````````````Q=(\"!!!!````````````````````````````````"
	"````````!!!!!!!!!!!!!!!!!!!!````````````````````````````````````"
	"````````WNL;!!!!````````````````````````````````````````````!!!!"
	"!!!!\\/TM!!!!!!!!````````````````````````````````````````C)C)!!!!"
	"````````````````````````````````````````````````!!!!!!!!$!Q-!!!!"
	"!!!!````````````````````W>H:````````J+3E:76F!!!!````````````````"
	"````````````````````````````````````````````!!!!!!!!````````````"
	"````!!!!!!!!T]`0````P\\_`!!!!!!!!````````````````````````````````"
	"````````````````````````````````````````````````````!!!!!!!!!!!!"
	"````PL[_!!!!!!!!````````````````````````````````````````````````"
	"````````````````````````````````!!!!SML+!!!!!!!!TM\\/!!!!!!!!!!!!"
	"";

Clock::Clock(): App() {
	// Keep the constructor empty and do most things in the init()
}
void Clock::init() {
#ifdef CLOCK_DEBUG
	Serial.println("Clock::init()");
#endif
	m_noise = false;
	m_icon = new Icon(28,&clock_bitmap[0]);
	m_timeZone = configuration.getTimeZone();
#ifdef CLOCK_DEBUG
	Serial.print("m_timeZone=");
	Serial.println(m_timeZone);
#endif
}

void Clock::setup() {
#ifdef CLOCK_DEBUG
	Serial.println("Clock::setup()");
#endif
	Graphics.fillScreen(BLACK);
	Graphics.setRotation(3);
	m_buttonOn->draw();
	m_buttonOff->draw();
}

void Clock::close() {
#ifdef CLOCK_DEBUG
	Serial.println(PSTR("Clock::close()"));
#endif
	m_noise = false;
}

boolean Clock::touch(Point p) {
	if (m_buttonOn->isClicked(p)) {
		Serial.println(PSTR("clock::touch turning off noise"));
		m_buttonOn->flash();
		m_noise = false;
	}
	else if (m_buttonOff->isClicked(p)) {
		Serial.println(PSTR("clock::touch turning on noise"));
		m_buttonOff->flash();
		m_noise = true;
	}
#ifdef CLOCK_DEBUG
	Serial.print(PSTR("clock::touch m_noise="));
	Serial.println(m_noise);
#endif
	return true;
}
void Clock::display() {
	if (m_noise) {
		Serial.println(PSTR("clock::noise"));
		Hardware.playTone(3136,30,40);
		Hardware.playTone(4186,30,9);
		Hardware.blink1();
	}
	Graphics.fillRect(0,0,Graphics.width(),120,BLACK);
	Graphics.setCursor(60,50);
	Graphics.setTextColor(WHITE);
	Graphics.setTextSize(3);

	long adjustedDate = now() + (m_timeZone * SECS_PER_HOUR);

	Graphics.println(Hardware.timeString(adjustedDate));
	Graphics.setCursor(50,100);
	Graphics.println(Hardware.dateString(adjustedDate));
}

Clock::~Clock() {
}

App *clock = new Clock();


